Repository navigation
ci: harden the npm publish path - #1226
ParidelPooya wants to merge 9 commits into
Conversation
The publish job holds id-token: write, so code that runs in it can publish to npm. Its npm ci ran the install scripts of every monorepo dependency, including node-llama-cpp and electron-winstaller for the telemetry apps. The publish job needs none of them. npm ci --ignore-scripts skips those scripts. npm publish still runs the prepublishOnly and prepack scripts of our own packages. A local run of npm ci --ignore-scripts, npm run build and npm run test passed.
A tag such as actions/checkout@v7 can move to new code at any time. 49 action references used a tag. Four of them were aws-actions/configure-aws-credentials@v6, in jobs that assume an AWS role. otel-conformance-tests.yml called a reusable workflow at @main. The publish and Scorecard workflows already pinned by SHA. Each reference now names the commit SHA of its tag, with the version in a comment. The reusable workflow is pinned to the current main commit. Dependabot keeps SHA pins up to date. Its github-actions entry now also covers .github/actions/*, so the npm-ci composite action gets updates too.
The publish job ran for any published release, on any tagged commit. It had no approval step, and it did not run the package checks that pull requests run. So a release on an unreviewed commit, or a tarball with missing files, would go to npm. The job now: - runs in the npm-publish environment, so a repository admin can require a reviewer before it starts, - fails when the release tag is not on main or v1.x, - runs verify-declared-files-shipped.mjs and the core check:package (attw and publint) before it publishes, - holds id-token: write at the job level, not for the whole workflow. Every release tag since the history was squashed is on main, so the tag check accepts them.
CODEOWNERS covered the ADRs, a few core files and the prompts. It did not cover the workflows, the composite action, the Dependabot config, the package.json files, the lockfile or the root rollup config. Those files decide what CI runs, what the packages install and what gets published. They now need a review from the JS SDK maintainers. The rule takes effect when branch protection on main requires review from code owners.
This comment has been minimized.
This comment has been minimized.
The OTel conformance workflow loads the conformance tests from conformance_test_ref, which defaults to main. A SHA pin on the orchestrator ran an old orchestrator against new tests. templates.test.ts asserts the @main reference for that reason, and it failed on the pin. The reference is back on @main, with a comment that says why. The workflow is in the aws org and owned by the same team.
fetch-depth: 0 also fetches tags. Git resolves "origin/main" as a tag before it tries refs/remotes/origin/main. So a tag named origin/main on a commit outside main passed the check. The check now uses refs/remotes/origin/$branch. A local probe with such a tag passes the old form and rejects the new one.
This comment has been minimized.
This comment has been minimized.
The tag check had no test, and CONTRIBUTING.md rule 4 requires one for every condition. Rule 2 prefers removing logic to adding it. The npm-publish environment already requires a maintainer to approve each publish. The approval shows the tag and its commit. So the reviewer checks that the tag is on main or v1.x, and the job keeps no logic for it. fetch-depth: 0 served only that check, so it goes too.
This comment has been minimized.
This comment has been minimized.
Each published package has its own build config: rollup.config.mjs, tsconfig.build.json or esbuild.mjs. These files decide what goes into the tarball. CODEOWNERS covered only the root rollup config. The three package patterns now need a review from the JS SDK maintainers.
SilanHe
left a comment
There was a problem hiding this comment.
Thanks, the feedback is addressed. Please create the npm-publish environment with required reviewers before the next release, since until then a release publishes with no approval.
🤖 AI-assisted comment
This comment has been minimized.
This comment has been minimized.
| # reviewer checks that the release tag is on main or v1.x. | ||
| environment: npm-publish |
There was a problem hiding this comment.
Codex AI review · Finding arf_v1_rerhdxtlmexlh4u6f5vudgkosl
[P1] Bind the approved release to the checkout commit. The new gate asks reviewers to check the release tag, but checkout still receives the unqualified github.event.release.tag_name. The pinned checkout's getCheckoutInfo prefers a matching branch over a tag. If someone creates a branch with the release tag's name, the tag can remain immutable and on main while this approved job builds and publishes the branch's code with id-token: write. Set checkout's ref to ${{ github.sha }} and have the reviewer verify that same commit, so approval and publishing use identical source. Include regression coverage for a branch/tag name collision.
To suppress repeats, reply /ai verdict deferred, /ai verdict false-positive, or /ai verdict out-of-scope on the first nonblank line. Add rationale on later lines. A new /ai verdict accepted allows future repeats again.
Codex AI reviewOne blocking issue in Reviewed commit |
Part of #1225.
Summary
The publish job can publish every package in this repo to npm. This PR limits what can run in that job and what it can publish. Each commit fixes one item from #1225.
npm ciran the install scripts of every monorepo dependency while the job heldid-token: write. Examples arenode-llama-cppandelectron-winstaller, which only the telemetry apps need.npm ci --ignore-scripts.npm publishstill runs theprepublishOnlyandprepackscripts of our own packages.uses:references to third-party actions used a tag. Four wereaws-actions/configure-aws-credentials@v6in jobs that assume an AWS role..github/actions/*.npm-publishenvironment, so a maintainer approves each publish and checks that the tag is onmainorv1.x. It runsverify-declared-files-shipped.mjsand the corecheck:packagebefore it publishes.id-token: writemoves from the workflow to the job.package.jsonfiles, the lockfile and the build configs had no code owner.Before merge: a repository admin creates the environment
The
npm-publishenvironment does not exist yet. If it is missing when a release runs, GitHub creates it with no protection rules. So the approval step only works after an admin does this:npm-publish.After the first release through this gate: bind the trusted publisher
A release runs the
npm-publish.ymlof the tagged commit. The copy onv1.xand on every older tag has noenvironment:and runs plainnpm ci. So a release on such a commit skips this gate.The npm trusted publisher settings name no environment today. A package maintainer on npmjs.com binds the trusted publisher of each published package to the
npm-publishenvironment. Then npm rejects a publish from any workflow copy without that environment. This step is required. Without it, the gate covers only releases tagged onmain.Testing
npm ci --ignore-scripts,npm run buildandnpm run testpass locally. These are the publish job's steps.verify-declared-files-shipped.mjsandnpm run check:package -w packages/aws-durable-execution-sdk-jspass on that install.Not pinned
The OTel conformance workflow still calls
opentelemetry-orchestrator.yml@main. It loads the conformance tests fromconformance_test_ref, which also defaults tomain. A SHA pin would run an old orchestrator against new tests, andtemplates.test.tsasserts the@mainreference. The workflow is in theawsorg and owned by the same team.